package com.imooc.rabbit.producer.service;

import com.imooc.rabbit.producer.constant.BrokerMessageStatus;
import com.imooc.rabbit.producer.entity.BrokerMessage;
import com.imooc.rabbit.producer.mapper.BrokerMessageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @description: 可靠性消息 数据库相关的业务逻辑
 * @author: Yz
 * @create: 2020-10-12 14:51
 **/
@Service
public class MessageStoreService {

    @Autowired
    private BrokerMessageMapper brokerMessageMapper;

    public int insert(BrokerMessage brokerMessage){
        return brokerMessageMapper.insert(brokerMessage);
    }

    public void success(String messageId){
        brokerMessageMapper.changeBrokerMessageStatus(messageId, BrokerMessageStatus.SEND_OK.getCode(),new Date());
    }

    public void fail(String messageId){
        brokerMessageMapper.changeBrokerMessageStatus(messageId, BrokerMessageStatus.SEND_FAIL.getCode(),new Date());
    }
}
